package com.otheima.homeweek;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Scanner;

public class Demo03 {//键盘录入一个年份，判断这个年份是平年还是闰年（提示，闰年2月有29天，平年2月只有28天）

    public static void main(String[] args) {
        //键盘录入年份
        System.out.println("请录入一个年分");
        Scanner sc = new Scanner(System.in);
        int year =sc.nextInt();
        LocalDate localDate = LocalDate.of(year, 3, 1);
        //减到最后一天
        LocalDate nowLocalDate = localDate.plusDays(-1);
        int dayOfMonth = nowLocalDate.getDayOfMonth();
        //根据二月的天数判断
        if(dayOfMonth == 28){
            System.out.println("平年");
        }else{
            System.out.println("闰年");
        }
    }

    public static void Test(){
        //键盘录入年份
        System.out.println("请录入一个年分");
        Scanner sc = new Scanner(System.in);
        int s =sc.nextInt();
        //格式化
        String s1 = "2001-08-05";
        DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        LocalDate year = LocalDate.parse(s1, pattern);
        year.withYear(s);
        //判断平年还是闰年
        if(year.getDayOfYear() == 365){
            System.out.println("这是平年");
        }else{
            System.out.println("这是闰年");
        }
    }
}
